package com.skywoody.barcode;

import static org.junit.Assert.*;

import org.junit.Test;

public class BarcodeUtilTests {
	
	private static String VALID_BARCODE1 = "6922848641136";
	
	private static String VALID_BARCODE2 = "6922266440007";
	
	private static String VALID_ISBNCODE = "9787810900218";
	
	private static String INVALID_BARCODE1 = "3921266440007";
	
	private static String INVALID_BARCODE2 = "392126644007";
	
	private static String VALID_ISBN = "7560038794";

	@Test
	public void testCaculateCheckDigit() {
		assertEquals('7', BarcodeUtil.caculateCheckDigit(VALID_BARCODE2));
		assertEquals('6', BarcodeUtil.caculateCheckDigit(VALID_BARCODE1));
	}

	@Test
	public void testIsBarcode() {
		assertTrue(BarcodeUtil.isBarcode(VALID_BARCODE1));
		assertFalse(BarcodeUtil.isBarcode(INVALID_BARCODE1));
		assertFalse(BarcodeUtil.isBarcode(INVALID_BARCODE2));
		assertTrue(BarcodeUtil.isBarcode(VALID_ISBN));
		assertTrue(BarcodeUtil.isBarcode(VALID_ISBNCODE));
	}
	
	@Test
	public void testISBN10ToEan13() {
		assertEquals("9787308031301", BarcodeUtil.iSBN10ToEan13("7308031306"));
		assertEquals("9787500544845", BarcodeUtil.iSBN10ToEan13("7500544847"));
	}

}
